//
//  AddEducationViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/30.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "AddEducationViewController.h"


@interface AddEducationViewController ()<MCDatePickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *strSchoolName;
@property (weak, nonatomic) IBOutlet UITextField *strProfessionalName;
@property (weak, nonatomic) IBOutlet UITextField *strRecord;
@property (weak, nonatomic) IBOutlet UITextField *strGraduationTime;

@property (weak, nonatomic) IBOutlet UIView *showButton;

@property (nonatomic, strong) UIButton *navRightButton;
@end

@implementation AddEducationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = strColor(@"f6f6f6");
    // right item
    self.navRightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    if (_indexEdit == 1) {
        TitleView(@"教育经历")
        _showButton.hidden = NO;
        [self.navRightButton setImage:[UIImage imageNamed:@"icon_news_delete"] forState:UIControlStateNormal];
        self.navRightButton.imageEdgeInsets = UIEdgeInsetsMake(0,15, 0, -15);
        // 传值
        _strSchoolName.text = _editSchoolName;
        _strProfessionalName.text = _editProfessionalName;
        _strRecord.text = _editRecord;
        _strGraduationTime.text = _editGraduationTime;
        
    }else{
        TitleView(@"添加教育经历")
        [self.navRightButton setTitle:@"提交" forState:UIControlStateNormal];
        self.navRightButton.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, -10);
        self.navRightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.navRightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    // 事件绑定
   [self.navRightButton addTarget:self action:@selector(navActions) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)navActions{
    if (_indexEdit == 1) {
        
        _strSchoolName.text = @"";
        _strProfessionalName.text = @"";
        _strRecord.text = @"";
        _strGraduationTime.text = @"";
        __weak typeof(self) weakSelf = self;
        if (weakSelf.education) {
            weakSelf.education(_strSchoolName.text, _strProfessionalName.text, _strRecord.text, _strGraduationTime.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        
        if (_strSchoolName.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写你的毕业学校");
            return;
        }
        if (_strProfessionalName.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写专业名称");
            return;
        }
        if (_strRecord.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择学历");
            return;
        }
        if (_strGraduationTime.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择毕业时间");
            return;
        }
    
        __weak typeof(self) weakSelf = self;
        if (weakSelf.education) {
            weakSelf.education(_strSchoolName.text, _strProfessionalName.text, _strRecord.text, _strGraduationTime.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
}


- (IBAction)btnRecord:(id)sender {
    
    NSArray * educationArray = @[@"初中",@"高中",@"中专",@"大专",@"本科",@"博士",@"硕士"];
    zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:educationArray andHeadTitle:@"学历" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        _strRecord.text = choiceString;
        [pickerView dismissPicker];
    }];
    [pickerView show];
    
}


- (IBAction)btnGraduationTime:(id)sender {
    
    MCDatePickerView *yearView = [[MCDatePickerView alloc] initWithFrame:CGRectZero type:XMGStyleTypeYear];
    yearView.delegate = self;
    [yearView show];
}
-(void)didSelectDateResult:(NSString *)resultDate{
        self.strGraduationTime.text = [resultDate substringToIndex:4];
}

- (IBAction)btnSave:(id)sender {
    
    if (_strSchoolName.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写你的毕业学校");
        return;
    }
    if (_strProfessionalName.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写专业名称");
        return;
    }
    if (_strRecord.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择学历");
        return;
    }
    if (_strGraduationTime.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择毕业时间");
        return;
    }
    
    if (_strSchoolName.text == _editSchoolName &&
        _strProfessionalName.text == _editProfessionalName &&
        _strRecord.text == _editRecord &&
        _strGraduationTime.text == _editGraduationTime) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    if (weakSelf.education) {
        weakSelf.education(_strSchoolName.text, _strProfessionalName.text, _strRecord.text, _strGraduationTime.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    
}


@end
